#+TITLE: GNU Plot Cheatsheet
* Introduction
  Gnuplot is Gnu's program to let you plot 2D and 3D graphs.  It is amazing what it can do.

  - A simple Example
    #+BEGIN_SRC gnuplot
      Title = "Hello World"
      set logscale x
      set arrow 100,5 rto 10,2
    #+END_SRC

    #+RESULTS:

    #+BEGIN_SRC gnuplot
      Title = "Absolute Value of X"
      plot abs(x)
    #+END_SRC

    #+RESULTS:

    #+BEGIN_SRC gnuplot
      plot ceil (x)
    #+END_SRC

    #+RESULTS:

    #+BEGIN_SRC gnuplot
      # set polar
      plot cos (x)
    #+END_SRC

    #+RESULTS:

    #+BEGIN_SRC gnuplot
      plot cosh (x) lt rgb "violet"
    #+END_SRC

    #+RESULTS:

* Plotting commands
  Gnuplot uses 3 different commands to create a plot: *splot* (3D graphs), *plot* (2D) graphs. *replot*

  Plot operates in rectangular or polor cordinates.  ie: set polar
  Plot lets you use each of the 4 borders as axises.  *x* (bottom), *x2* (top), *y* (left), *y2* (right)

  Splot operates in cartesian coordinates, but it can also plot surfaces with isosamples [[info:gnuplot#isosamples][info:gnuplot#isosamples]]

Plot also lets you use each of the four borders – x (bottom), x2 (top), y (left) and y2 (right) – as an independent axis. The axes option lets you choose which pair of axes a given function or data set is plotted against. A full complement of set commands exists to give you complete control over the scales and labelling of each axis. Some commands have the name of an axis built into their names, such as set xlabel. Other commands have one or more axis names as options, such as set logscale xy. Commands and options controlling the z axis have no effect on 2D graphs.

I probably want to plot via a histogram.  http://www.gnuplotting.org/manpage-gnuplot-4-6/#Q1-1-147

* Basic Syntax
  Options and accompanying parameters are separated by spaces.  Lines and coordinater are separated by commans.  Ranges are
  separated by colons and enclosed in brackets.  Text and file names are enclosed in quotation marks.

* Plotting styles
  Gnuplot comes with many different plotting styles.  Some of the popular ones are:
  - boxes
  - boxplot
  - circles
  - ellipses
  - dots
  - filledcurves
  - lines
  - polar
  - points

    In one plot you can mix different plotting styles ie:

    #+BEGIN_SRC gnuplot
      set style fill pattern
      plot sin(x) with boxes, cos(x) with lines
    #+END_SRC

    #+RESULTS:

    #+BEGIN_SRC gnuplot
      plot x**3 - 5x**2
    #+END_SRC

    #+RESULTS:

* One can plot date from a data file too
http://www.gnuplotting.org/plotting-data/

Let's say we have a data file with the contents:

# plotting_data1.dat
# X   Y
  1   2
  2   3
  3   2
  4   1

Then we could plot a line through the data like so:

# Set linestyle 1 to blue (#0060ad)
set style line 1 \
    linecolor rgb '#0060ad' \
    linetype 1 linewidth 2 \
    pointtype 7 pointsize 1.5

plot 'plotting_data1.dat' with linespoints linestyle 1


     #+PLOT: title:"Collatz" ind:1 deps:(3) type:2d with:lines set:"yrange [0:]"
     | Sede      | Max cites | H-index |
     |-----------+-----------+---------|
     | Chile     |    257.72 |   21.39 |
     | Leeds     |    165.77 |   19.68 |
     | Sao Paolo |     71.00 |   11.50 |
     | Stockholm |    134.19 |   14.33 |
     | Morelia   |    257.56 |   17.67 |
